package com.library.servlet.user;

import com.library.dao.BorrowRecordDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/borrowRecords")
public class BorrowRecordServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int userId = ((com.library.entity.User) session.getAttribute("user")).getId();

        BorrowRecordDAO recordDAO = new BorrowRecordDAO();
        List<com.library.entity.BorrowRecord> records = recordDAO.getBorrowRecordsByUser(userId);
        request.setAttribute("records", records);
        request.getRequestDispatcher("/user/borrowRecordList.jsp").forward(request, response);
    }
}    